package com.ruoyi.web.controller.counter;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.counter.domain.Oprecords;
import com.ruoyi.counter.service.IOprecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 器具使用记录Controller
 *
 * @author xll
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/counter/oprecords")
public class OprecordsController extends BaseController
{
    @Autowired
    private IOprecordsService oprecordsService;

    /**
     * 查询器具使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('counter:oprecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(Oprecords oprecords)
    {
        startPage();
        List<Oprecords> list = oprecordsService.selectOprecordsList(oprecords);
        return getDataTable(list);
    }

    /**
     * 导出器具使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('counter:oprecords:export')")
    @Log(title = "器具使用记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Oprecords oprecords)
    {
        List<Oprecords> list = oprecordsService.selectOprecordsList(oprecords);
        ExcelUtil<Oprecords> util = new ExcelUtil<Oprecords>(Oprecords.class);
        return util.exportExcel(list, "器具使用记录数据");
    }

    /**
     * 获取器具使用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('counter:oprecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(oprecordsService.selectOprecordsById(id));
    }

    /**
     * 新增器具使用记录
     */
    @PreAuthorize("@ss.hasPermi('counter:oprecords:add')")
    @Log(title = "器具使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Oprecords oprecords)
    {
        return toAjax(oprecordsService.insertOprecords(oprecords));
    }

    /**
     * 修改器具使用记录
     */
    @PreAuthorize("@ss.hasPermi('counter:oprecords:edit')")
    @Log(title = "器具使用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Oprecords oprecords)
    {
        return toAjax(oprecordsService.updateOprecords(oprecords));
    }

    /**
     * 删除器具使用记录
     */
    @PreAuthorize("@ss.hasPermi('counter:oprecords:remove')")
    @Log(title = "器具使用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oprecordsService.deleteOprecordsByIds(ids));
    }
}
